package com.module.sysconfig.controller;

import java.io.IOException;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.module.sysconfig.service.TpfpzbService;
import com.support.helper.AjaxHelper;
import com.support.jdbc.Page;
import com.support.util.StringUtils;
import com.support.web.ControllerSupport;
/**
 * 通配符配置表
 */
@Controller
@Scope(value = "prototype")
@RequestMapping("/sysconfig/tpfpzb")
public class TpfpzbController extends ControllerSupport 
{

	private final Logger logger = LoggerFactory.getLogger(this.getClass()); 
	
	@Autowired
	private TpfpzbService tpfpzbService;
	
	/**
	 * 保存通配符配置表数据
	 * @throws IOException
	 */
	@RequestMapping("/saveTpfpzb")
	public void saveTpfpzb() throws IOException
	{
		try
		{
			Map<String, String> paramsMap = this.getParamsMap();
			tpfpzbService.saveTpfpzb(paramsMap);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.SUCCESS, "保存通配符配置表成功！"));
		}
		catch(Exception e)
		{
			e.printStackTrace();
			logger.error("TpfpzbController.saveTpfpzb:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
		}
	}
	
	/**
	 * 修改通配符配置表
	 * @throws IOException
	 */
	@RequestMapping("/updateTpfpzb")
	public void updateTpfpzb() throws IOException
	{
		try 
		{
			
			Map<String, String> paramsMap = this.getParamsMap();
			tpfpzbService.updateTpfpzb(paramsMap);
			
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.SUCCESS, "修改通配符配置表数据成功！"));
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error("TpfpzbController.updateTpfpzb:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
		}
	}
	
	/**
	 * 删除通配符配置表数据
	 * @throws IOException
	 */
	@RequestMapping("/deleteTpfpzb")
	public void deleteTpfpzb() throws IOException
	{
		try
		{
			Map<String, String> params = this.getParamsMap();
			
			String id = params.get("ID");
			
			if(StringUtils.isNullOrEmpty(params.get("ID")))
			{
				returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, "参数错误，ID未传"));
			}
			else
			{
				if(!StringUtils.isNumeric(params.get("ID")))
				{
					returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, "参数错误，ID不是数据类型"));
				}
				else{
					tpfpzbService.deleteTpfpzb(Long.parseLong(id));
					returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.SUCCESS, "删除通配符配置表数据成功！"));
				}
			}
		}
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error("TpfpzbController.deleteTpfpzb:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
		}
	}
	
	/**
	 * 查询通配符配置表数据
	 * @throws IOException
	 */
	@SuppressWarnings("rawtypes")
	@RequestMapping("/queryTpfpzbRecord")
	public void queryTpfpzbRecord() throws IOException
	{
		try
		{
			Page page = this.getParamsPage();
			page = tpfpzbService.queryTpfpzbRecord(page);
			returnJSONView(AjaxHelper.toJSON(page, AjaxHelper.SUCCESS, "查询通配符配置表数据成功！"));
		}
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error("TpfpzbController.queryTpfpzbRecord:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
		}
	}
}
 